<!DOCTYPE html>
<html lang="zh-cn">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <meta name="referrer" content="no-referrer" />
  <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.js"></script>
  <script src="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js" integrity="sha384-aJ21OjlMXNL5UyIl/XNwTMqvzeRMZH2w8c5cRVpzpU8Y5bApTppSuUkhZXN0VxHd" crossorigin="anonymous"></script>
  <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">
  <style>
    .goods-list{
      width: 980px;
      margin: 0 auto;
    }
    .pic{
      width: 232px;
      height: 148px;
    }
    .goods{
      width: 400px;
      height: 500px;
      position: fixed;
      background-color: #fff;
      color: #333;
      text-align: left;
      padding: 50px 30px 30px 30px;
      border-radius: 20px;
      box-shadow: rgb(0 0 0 / 35%) 0px 5px 15px;
      top: 0;bottom: 0;left: 0;right: 0;
      margin: auto;
      display: none;
    }
    .po-r{
      position: relative;
    }
    #remove{
      position: absolute;
      right: -10px;
      top: -30px;
    }
  </style>
</head>
<body>
  <div id="app">
    <nav class="navbar navbar-inverse">
      <div class="container-fluid">
        <!-- Brand and toggle get grouped for better mobile display -->
        <div class="navbar-header">
          <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
          <a class="navbar-brand" href="#">KeyBoard</a>
        </div>
    
        <!-- Collect the nav links, forms, and other content for toggling -->
        <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
          <ul class="nav navbar-nav">
            <li ><a href="/home">home</a></li>
            <li class="dropdown">
              <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">商品 <span class="caret"></span></a>
              <ul class="dropdown-menu">
                <li><a href="/home/switch">Switch</a></li>
                <li><a href="/home/box">Box</a></li>
                <li><a href="/home/gmk">GMK</a></li>
              </ul>
            </li>
          </ul>
          <ul class="nav navbar-nav navbar-right">
            <li class="dropdown">
              <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Options <span class="caret"></span></a>
              <ul class="dropdown-menu">
                <li><a href="/login">退出登录</a></li>
                <li><a href="#">修改密码</a></li>
              </ul>
            </li>
          </ul>
        </div><!-- /.navbar-collapse -->
      </div><!-- /.container-fluid -->
    </nav>
    
    <div class="goods-list">

      <h1>GMK</h1>

      <div id="btn" class="btn btn-warning">
        添加商品
      </div>

      <div id="goods" class="goods">
        <div class="po-r">
          <div id="remove" class="btn btn-danger">X</div>
          <form action="/doForm" method="POST" role="form">
              <div class="form-group">
                  <label for="">请选择商品种类</label>
                  
                  <select name="type" id="input" class="form-control" required="required">
                    <option value="gmk">gmk</option>
                    <option value="switch">switch</option>
                    <option value="box">box</option>
                  </select>
                  
              </div>
              <div class="form-group">
                  <label for="">名字</label>
                  <input type="text" class="form-control" name="name" id="" placeholder="请输入商品名字">
              </div>
              <div class="form-group">
                  <label for="">价格</label>
                  <input type="text" class="form-control" name="price" id="" placeholder="请输入商品价格">
              </div>
              <div class="form-group">
                  <label for="">描述</label>
                  <input type="text" class="form-control" name="detail" id="" placeholder="请输入商品描述">
              </div>
              <div class="form-group">
                  <label for="">图片</label>
                  <label for=""><a href="https://sm.ms/" target="_blank">将图片转换为url地址</a></label>
                  <input type="url" class="form-control" name="img" id="" placeholder="请输入商品图片的url地址">
              </div>
          
              <button type="submit" class="btn btn-primary">商品上传</button>
          </form>
        </div>
        
      </div>

      <table class="table table-hover">
        <thead>
          <tr>
            <th>序号</th>
            <th>名字</th>
            <th>图片</th>
            <th>价格</th>
            <th>删除</th>
          </tr>
        </thead>
        <tbody class="content">
          {% for item in res %}
          <tr>
            <td>{{loop.index}}</td>
            <td>{{item.name}}</td>
            <td>
              <img class="pic" src="{{item.img}}" alt="">
            </td>
            <td>{{item.price}}</td>
            <td>
              <button  data-aid="{{item._id}}" class="btn btn-danger">删除</button>
            </td>
          </tr>
          {% endfor %}
        </tbody>
      </table>
      

    </div>
  </div>
  <script>
    $('#btn').click(function (even) {
      $('#goods').toggle()
    })
    $('#remove').click(function(even){
      $('#goods').toggle()
    })
    $('.content button').click((event) =>{
      // console.log(event.target.dataset.aid);
      var id = event.target.dataset.aid
      if(confirm('确认删除吗？')){
        window.location.href = `/doRemove?id=${id}`
      }
    })
  </script>
</body>
</html>